{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from ckbqa.dataset.data_prepare import get_raw_data_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_df = get_raw_data_df()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>question</th>\n",
       "      <th>answer</th>\n",
       "      <th>sparql</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>4000</td>\n",
       "      <td>4000</td>\n",
       "      <td>4000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>unique</th>\n",
       "      <td>3988</td>\n",
       "      <td>2930</td>\n",
       "      <td>3965</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>top</th>\n",
       "      <td>[科学家牛顿的英文名是？]</td>\n",
       "      <td>&lt;疾病&gt;</td>\n",
       "      <td>select ?x where { &lt;大华股份&gt; &lt;市盈率&gt; ?x. }</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>freq</th>\n",
       "      <td>3</td>\n",
       "      <td>253</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             question answer                                sparql\n",
       "count            4000   4000                                  4000\n",
       "unique           3988   2930                                  3965\n",
       "top     [科学家牛顿的英文名是？]   <疾病>  select ?x where { <大华股份> <市盈率> ?x. }\n",
       "freq                3    253                                     3"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>question</th>\n",
       "      <th>answer</th>\n",
       "      <th>sparql</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[莫妮卡·贝鲁奇的代表作？]</td>\n",
       "      <td>&lt;西西里的美丽传说&gt;</td>\n",
       "      <td>select ?x where { &lt;莫妮卡·贝鲁奇&gt; &lt;代表作品&gt; ?x. }</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[《湖上草》是谁的诗？]</td>\n",
       "      <td>&lt;柳如是_（明末“秦淮八艳”之一）&gt;</td>\n",
       "      <td>select ?x where { ?x &lt;主要作品&gt; &lt;湖上草&gt;. }</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>[龙卷风的英文名是什么？]</td>\n",
       "      <td>\"Tornado\"</td>\n",
       "      <td>select ?x where { &lt;龙卷风_（一种自然天气现象）&gt; &lt;外文名&gt; ?x. }</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[新加坡的水域率是多少？]</td>\n",
       "      <td>\"1.444%\"</td>\n",
       "      <td>select ?x where { &lt;新加坡&gt; &lt;水域率&gt; ?x. }</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>[商朝在哪场战役中走向覆灭？]</td>\n",
       "      <td>&lt;牧野之战&gt;</td>\n",
       "      <td>select ?x where { &lt;商朝&gt; &lt;灭亡&gt; ?x. }</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          question              answer  \\\n",
       "0   [莫妮卡·贝鲁奇的代表作？]          <西西里的美丽传说>   \n",
       "1     [《湖上草》是谁的诗？]  <柳如是_（明末“秦淮八艳”之一）>   \n",
       "2    [龙卷风的英文名是什么？]           \"Tornado\"   \n",
       "3    [新加坡的水域率是多少？]            \"1.444%\"   \n",
       "4  [商朝在哪场战役中走向覆灭？]              <牧野之战>   \n",
       "\n",
       "                                           sparql  \n",
       "0        select ?x where { <莫妮卡·贝鲁奇> <代表作品> ?x. }  \n",
       "1            select ?x where { ?x <主要作品> <湖上草>. }  \n",
       "2  select ?x where { <龙卷风_（一种自然天气现象）> <外文名> ?x. }  \n",
       "3             select ?x where { <新加坡> <水域率> ?x. }  \n",
       "4               select ?x where { <商朝> <灭亡> ?x. }  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_df['q_len'] = data_df['question'].apply(len)\n",
    "data_df['a_len'] = data_df['answer'].apply(len)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>question</th>\n",
       "      <th>answer</th>\n",
       "      <th>sparql</th>\n",
       "      <th>q_len</th>\n",
       "      <th>a_len</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[莫妮卡·贝鲁奇的代表作？]</td>\n",
       "      <td>&lt;西西里的美丽传说&gt;</td>\n",
       "      <td>select ?x where { &lt;莫妮卡·贝鲁奇&gt; &lt;代表作品&gt; ?x. }</td>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[《湖上草》是谁的诗？]</td>\n",
       "      <td>&lt;柳如是_（明末“秦淮八艳”之一）&gt;</td>\n",
       "      <td>select ?x where { ?x &lt;主要作品&gt; &lt;湖上草&gt;. }</td>\n",
       "      <td>1</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>[龙卷风的英文名是什么？]</td>\n",
       "      <td>\"Tornado\"</td>\n",
       "      <td>select ?x where { &lt;龙卷风_（一种自然天气现象）&gt; &lt;外文名&gt; ?x. }</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[新加坡的水域率是多少？]</td>\n",
       "      <td>\"1.444%\"</td>\n",
       "      <td>select ?x where { &lt;新加坡&gt; &lt;水域率&gt; ?x. }</td>\n",
       "      <td>1</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>[商朝在哪场战役中走向覆灭？]</td>\n",
       "      <td>&lt;牧野之战&gt;</td>\n",
       "      <td>select ?x where { &lt;商朝&gt; &lt;灭亡&gt; ?x. }</td>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          question              answer  \\\n",
       "0   [莫妮卡·贝鲁奇的代表作？]          <西西里的美丽传说>   \n",
       "1     [《湖上草》是谁的诗？]  <柳如是_（明末“秦淮八艳”之一）>   \n",
       "2    [龙卷风的英文名是什么？]           \"Tornado\"   \n",
       "3    [新加坡的水域率是多少？]            \"1.444%\"   \n",
       "4  [商朝在哪场战役中走向覆灭？]              <牧野之战>   \n",
       "\n",
       "                                           sparql  q_len  a_len  \n",
       "0        select ?x where { <莫妮卡·贝鲁奇> <代表作品> ?x. }      1     10  \n",
       "1            select ?x where { ?x <主要作品> <湖上草>. }      1     18  \n",
       "2  select ?x where { <龙卷风_（一种自然天气现象）> <外文名> ?x. }      1      9  \n",
       "3             select ?x where { <新加坡> <水域率> ?x. }      1      8  \n",
       "4               select ?x where { <商朝> <灭亡> ?x. }      1      6  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
